<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>在职人员</title>
		<style type="text/css">
			body,
			html {
				width: 100%;
				height: 100%;
			}
			
			#addUser {
				display: none;
				position: fixed;
				left: 500px;
				top: 100px;
			}
		</style>
		<!-- Bootstrap core CSS-->
		<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
		<!-- Custom fonts for this template-->
		<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
		<!-- Custom styles for this template-->
		<link href="css/sb-admin.css" rel="stylesheet">
	</head>

	<body class="fixed-nav sticky-footer bg-dark" id="page-top">
		<!-- Navigation-->
		<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top" id="mainNav">
			<a class="navbar-brand" href="index.html">PMS</a>
			<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
			<div class="collapse navbar-collapse" id="navbarResponsive">
				<ul class="navbar-nav navbar-sidenav" id="exampleAccordion">
					<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Dashboard">
						<a class="nav-link" href="index.html">
							<i class="fa fa-fw fa-dashboard"></i>
							<span class="nav-link-text">首页</span>
						</a>
					</li>
					<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
						<a class="nav-link" href="charts.html">
							<i class="fa fa-fw fa-area-chart"></i>
							<span class="nav-link-text">人员管理</span>
						</a>
					</li>
					<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Tables">
						<a class="nav-link" href="tables.html">
							<i class="fa fa-fw fa-table"></i>
							<span class="nav-link-text">职位管理</span>
						</a>
					</li>
					<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Components">
						<a class="nav-link nav-link-collapse collapsed" data-toggle="collapse" href="#collapseComponents" data-parent="#exampleAccordion">
							<i class="fa fa-fw fa-wrench"></i>
							<span class="nav-link-text">人员录入</span>
						</a>
						<ul class="sidenav-second-level collapse" id="collapseComponents">
						</ul>
					</li>
					<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Example Pages">
						<a class="nav-link nav-link-collapse collapsed" data-toggle="collapse" href="#collapseExamplePages" data-parent="#exampleAccordion">
							<i class="fa fa-fw fa-file"></i>
							<span class="nav-link-text">人员管理系统登陆</span>
						</a>
						<ul class="sidenav-second-level collapse" id="collapseExamplePages">
							<li>
								<a href="login.html">登陆</a>
							</li>
							<li>
								<a href="register.html">注册</a>
							</li>
						</ul>
					</li>
					<li class="nav-item" data-toggle="tooltip" data-placement="right" title="Link">
						<a class="nav-link" href="#">
							<i class="fa fa-fw fa-link"></i>
							<span class="nav-link-text">系统设置</span>
						</a>
					</li>
				</ul>
				<ul class="navbar-nav sidenav-toggler">
					<li class="nav-item">
						<a class="nav-link text-center" id="sidenavToggler">
							<i class="fa fa-fw fa-angle-left"></i>
						</a>
					</li>
				</ul>
				<ul class="navbar-nav ml-auto">
					<li class="nav-item dropdown">
						<a class="nav-link dropdown-toggle mr-lg-2" id="messagesDropdown" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
							<i class="fa fa-fw fa-envelope"></i>
							<span class="d-lg-none">Messages
              <span class="badge badge-pill badge-primary">12 New</span>
							</span>
							<span class="indicator text-primary d-none d-lg-block">
              <i class="fa fa-fw fa-circle"></i>
            </span>
						</a>
						<div class="dropdown-menu" aria-labelledby="messagesDropdown">
							<h6 class="dropdown-header">New Messages:</h6>
							<div class="dropdown-divider"></div>
							<a class="dropdown-item" href="#">
								<strong>David Miller</strong>
								<span class="small float-right text-muted">11:21 AM</span>
								<div class="dropdown-message small">Hey there! This new version of SB Admin is pretty awesome! These messages clip off when they reach the end of the box so they don't overflow over to the sides!</div>
							</a>
							<div class="dropdown-divider"></div>
							<a class="dropdown-item" href="#">
								<strong>Jane Smith</strong>
								<span class="small float-right text-muted">11:21 AM</span>
								<div class="dropdown-message small">I was wondering if you could meet for an appointment at 3:00 instead of 4:00. Thanks!</div>
							</a>
							<div class="dropdown-divider"></div>
							<a class="dropdown-item" href="#">
								<strong>John Doe</strong>
								<span class="small float-right text-muted">11:21 AM</span>
								<div class="dropdown-message small">I've sent the final files over to you for review. When you're able to sign off of them let me know and we can discuss distribution.</div>
							</a>
							<div class="dropdown-divider"></div>
							<a class="dropdown-item small" href="#">View all messages</a>
						</div>
					</li>
					<li class="nav-item dropdown">
						<a class="nav-link dropdown-toggle mr-lg-2" id="alertsDropdown" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
							<i class="fa fa-fw fa-bell"></i>
							<span class="d-lg-none">Alerts
              <span class="badge badge-pill badge-warning">6 New</span>
							</span>
							<span class="indicator text-warning d-none d-lg-block">
              <i class="fa fa-fw fa-circle"></i>
            </span>
						</a>
						<div class="dropdown-menu" aria-labelledby="alertsDropdown">
							<h6 class="dropdown-header">New Alerts:</h6>
							<div class="dropdown-divider"></div>
							<a class="dropdown-item" href="#">
								<span class="text-success">
                <strong>
                  <i class="fa fa-long-arrow-up fa-fw"></i>Status Update</strong>
              </span>
								<span class="small float-right text-muted">11:21 AM</span>
								<div class="dropdown-message small">This is an automated server response message. All systems are online.</div>
							</a>
							<div class="dropdown-divider"></div>
							<a class="dropdown-item" href="#">
								<span class="text-danger">
                <strong>
                  <i class="fa fa-long-arrow-down fa-fw"></i>Status Update</strong>
              </span>
								<span class="small float-right text-muted">11:21 AM</span>
								<div class="dropdown-message small">This is an automated server response message. All systems are online.</div>
							</a>
							<div class="dropdown-divider"></div>
							<a class="dropdown-item" href="#">
								<span class="text-success">
                <strong>
                  <i class="fa fa-long-arrow-up fa-fw"></i>Status Update</strong>
              </span>
								<span class="small float-right text-muted">11:21 AM</span>
								<div class="dropdown-message small">This is an automated server response message. All systems are online.</div>
							</a>
							<div class="dropdown-divider"></div>
							<a class="dropdown-item small" href="#">View all alerts</a>
						</div>
					</li>
					<li class="nav-item">
						<form class="form-inline my-2 my-lg-0 mr-lg-2">
							<div class="input-group">
								<input class="form-control" type="text" placeholder="Search for...">
								<span class="input-group-btn">
                <button class="btn btn-primary" type="button">
                  <i class="fa fa-search"></i>
                </button>
              </span>
							</div>
						</form>
					</li>
					<li class="nav-item">
						<a class="nav-link" data-toggle="modal" data-target="#exampleModal">
							<i class="fa fa-fw fa-sign-out"></i>退出</a>
					</li>
				</ul>
			</div>
		</nav>
		<div class="content-wrapper">
			<div class="container-fluid">
				<!-- Breadcrumbs-->
				<ol class="breadcrumb">
					<li class="breadcrumb-item active">在职人员</li>
				</ol>
				<div class="add" style="color:red; width:100px; height:50px; text-align: center;cursor: pointer;">添加人员</div>

				<form action="http://localhost:3000/upload/img-upload" method="post" enctype="multipart/form-data" style="padding:20px;">
					上传头像
					<input type="text" name="user" id="user" value="" />
					<input type="file" name="myimg" id="myimg" value="" accept="image/*" />
					<input type="submit" value="提交" />
				</form>
				<div id="addUser" tabindex="-1" role="dialog" aria-labelledby="addUserModalLabel">
					<div class="modal-dialog" role="document" style="max-width:450px;">
						<form autocomplete="off" draggable="false">
							<div class="modal-content">
								<div class="modal-header">
									<h4 class="modal-title">增加用户</h4>
									<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" id='close'>&times;</span></button>

								</div>
								<div class="modal-body">
									<table class="table" style="margin-bottom:0px;">
										<thead>
											<tr> </tr>
										</thead>
										<tbody>
											<tr>
												<td wdith="20%">用户名:</td>
												<td width="80%"><input type="text" value="" class="form-control" id="username" name="username" maxlength="10" autocomplete="off" /></td>
											</tr>

											<tr>
												<td wdith="20%">电话:</td>
												<td width="80%"><input type="text" value="" class="form-control" id="usertel" name="usertel" maxlength="13" autocomplete="off" /></td>

											</tr>

											<tr>
												<td wdith="20%">密码:</td>
												<td width="80%"><input type="password" class="form-control" id="password" name="password" maxlength="18" autocomplete="off" /></td>

											</tr>

										</tbody>

									</table>
								</div>

								<div class="modal-footer">
									<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
									<button type="button" class="btn btn-primary" id="addUserBtn">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
				<div id="reviseUser" style="display: none; position:absolute;left:500px" role="dialog" aria-labelledby="addUserModalLabel">
					<div class="modal-dialog" role="document" style="max-width:450px;">
						<form autocomplete="off" draggable="false">
							<div class="modal-content">
								<div class="modal-header">
									<h4 class="modal-title">修改用户</h4>
									<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" id='close1'>&times;</span></button>

								</div>
								<div class="modal-body">
									<table class="table" style="margin-bottom:0px;">
										<thead>
											<tr> </tr>
										</thead>
										<tbody>
											<tr>
												<td wdith="20%">用户名:</td>
												<td width="80%"><input type="text" value="" class="form-control" id="username1" name="username1" maxlength="10" autocomplete="off" /></td>
											</tr>

											<tr>
												<td wdith="20%">电话:</td>
												<td width="80%"><input type="text" value="" class="form-control" id="usertel1" name="usertel1" maxlength="13" autocomplete="off" /></td>

											</tr>

											<tr>
												<td wdith="20%">密码:</td>
												<td width="80%"><input type="password" class="form-control" id="password1" name="password1" maxlength="18" autocomplete="off" /></td>

											</tr>

										</tbody>

									</table>
								</div>

								<div class="modal-footer">
									<button type="button" class="btn btn-default1" data-dismiss="modal">取消</button>
									<button type="button" class="btn btn-primary" id="addUserBtn1">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
				<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
					<thead>
						<tr style="text-align: center;">
							<th style="text-align: center;">ID</th>
							<th style="text-align: center;">用户名</th>
							<th style="text-align: center;">电话</th>
							<th style="text-align: center;">头像</th>
							<th style="text-align: center;">编辑</th>
							<th style="text-align: center;">删除</th>
							<th style="text-align: center;">状态</th>
							<th style="text-align: center;">是否登录</th>
						</tr>
					</thead>
					<tbody id="tblist">
					</tbody>
				</table>
				<!-- /.container-fluid-->
				<!-- /.content-wrapper-->
				<!-- Scroll to Top Button-->
				<a class="scroll-to-top rounded" href="#page-top">
					<i class="fa fa-angle-up"></i>
				</a>

				<!-- Logout Modal-->
				<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
					<div class="modal-dialog" role="document">
						<div class="modal-content">
							<div class="modal-header">
								<h5 class="modal-title" id="exampleModalLabel">准备离开</h5>
								<button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
							</div>
							<div class="modal-body">如果您准备结束当前会话，请选择下面的“退出”。</div>
							<div class="modal-footer">
								<button class="btn btn-secondary" type="button" data-dismiss="modal">取消</button>
								<a class="btn btn-primary" href="login.html">退出</a>
							</div>
						</div>
					</div>
				</div>
				<!-- Bootstrap core JavaScript-->
				<script src="vendor/jquery/jquery.min.js"></script>
				<script src="vendor/popper/popper.min.js"></script>
				<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
				<!-- Core plugin JavaScript-->
				<script src="vendor/jquery-easing/jquery.easing.min.js"></script>
				<!-- Custom scripts for all pages-->
				<script src="js/sb-admin.min.js"></script>
				<!-- Custom scripts for this page-->
				<!-- Toggle between fixed and static navbar-->
				<script>
					$('#toggleNavPosition').click(function() {
						$('body').toggleClass('fixed-nav');
						$('nav').toggleClass('fixed-top static-top');
					});
				</script>
				<!-- Toggle between dark and light navbar-->
				<script>
					$('#toggleNavColor').click(function() {
						$('nav').toggleClass('navbar-dark navbar-light');
						$('nav').toggleClass('bg-dark bg-light');
						$('body').toggleClass('bg-dark bg-light');
					});
				</script>
			</div>
	</body>
	<script type="text/javascript">
		$(function() {

			var baseUrl = "http://localhost:3000/";

			$('.add').on('click', function() {
				$('#addUser').css({
					display: 'block'
				});
				$('#close').on('click', function() {
					$('#addUser').css({
						display: 'none'
					});
				})
				$('.btn-default').on('click', function() {
					$('#addUser').css({
						display: 'none'
					});
				})
			})

			$.ajax({
				type: 'get',
				url: baseUrl + "users/readUser",
				success: function(data) {
					if(data == "0") {
						alert('没有用户');
					} else {
						//					console.log(data);
						for(var i in data) {
							var state = data[i].state;
							var str = "";
							if(state == "0") {
								str = "<span class='text-primary'>启用</span>"
							} else if(state == "1") {
								str = "<span class='text-danger'>禁用</span>"
							}
							var isLogin = data[i].isLogin;
							var loginStr = "";
							if(isLogin == "0") {
								loginStr = "否"
							} else if(isLogin == "1") {
								loginStr = "是"
							}
							//						console.log(data[i])
							var obj = "";
							obj += "<tr><td class='text-center'>" + (i * 1 + 1) + "</td><td class='text-center'>" + data[i].username + "</td><td class='text-center'>" + data[i].usertel + "</td><td class='text-center'><img src ='" + data[i].img + "' style='width:90px;height:90px;'/></td><td class='text-center myRevise' data-user=" + JSON.stringify(data[i]) + "><a href='javascript:;'>修改</a></td><td class='text-center myDelete' data-user=" + JSON.stringify(data[i]) + "><a href='javascript:;'>删除</a></td><td class='text-center myUser' data-user=" + JSON.stringify(data[i]) + " style='cursor:pointer'>" + str + "</td><td class='text-center'>" + loginStr + "</td></tr>";
							$("#tblist").append(obj);
						}

						$('.myUser').on('click', function() {
							var objstr = $(this).attr("data-user");
							//      	  console.log(objstr);
							var obb = JSON.parse(objstr);
							$.ajax({
								type: "get",
								url: baseUrl + "users/changeState",
								data: obb,
								success: function(data) {
									console.log(data);
									window.location.reload();
								}
							});
						})
						//点击删除删除对应的用户
						$('.myDelete').on('click', function() {
							var objstr = $(this).attr("data-user");
							console.log(objstr);
							var obb = JSON.parse(objstr);
							$.ajax({
								type: "get",
								url: baseUrl + "users/deleteUser",
								data: obb,
								success: function(data) {
									console.log(data);
									window.location.reload();
								}
							});
						})

						//点击修改用户信息
						$('.myRevise').on('click', function() {
							var objstr = $(this).attr("data-user");
							console.log(objstr);
							var obb = JSON.parse(objstr);
							console.log(obb)
							$('#addUser1').css({
								display: 'block'
							});
							$('#close1').on('click', function() {
								$('#reviseUser').css({
									display: 'none'
								});
							})
							$('.btn-default1').on('click', function() {
								$('#reviseUser').css({
									display: 'none'
								});
							})
							$('#reviseUser').css({
								display: 'block'
							});
							$('#addUserBtn1').click(function() {
								var username1 = $('#username1').val();
								var usertel1 = $('#usertel1').val();
								var password1 = $('#password1').val();
								console.log(username1+"-"+usertel1+"-"+password1);
								$.ajax({
									type: "get",
									url: baseUrl + "users/reviseUser",
									data: {
										username: username1,
										usertel: usertel1,
										password: password1
									},
									success: function(data) {
										console.log(data);
										window.location.reload();
									}
								});
							})

						})
					}
				}
			})

			$('#addUserBtn').on('click', function() {

				var username = $('#username').val();
				var usertel = $('#usertel').val();
				var password = $('#password').val();

				$.ajax({
					type: "get",
					url: baseUrl + "users/addUser",
					data: {
						username: username,
						usertel: usertel,
						password: password
					},
					success: function(data) {
						console.log(data);
						if(data == "0") {
							alert('用户已存在');
						} else {
							window.location.reload();
						}
					}
				});

			})

		})
	</script>

</html>